﻿using Common;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;

namespace CSC440TeamOne.MyNutrition.Views
{
    public class MyRecipePresenter : Presenter<IMyRecipeView>
    {
        private IMyNutritionController _controller;
        public MyRecipePresenter([CreateNew] IMyNutritionController controller)
        {
            _controller = controller;
        }

        public override void OnViewLoaded()
        {
            
        }

        public override void OnViewInitialized()
        {
            View.Show(_controller.LoadMyRecipeViewModelForCurrentUser());
        }

        public void OnSave()
        {
            var model = _controller.LoadMyRecipeViewModelForCurrentUser();
            View.update(model);
            _controller.saveViewRecipeModel(model);
            View.OnSaveViewCompleted(model);
        }

        public MyRecipeViewModel recipeSelected(int p)
        {
            var model = _controller.LoadMyRecipeViewModelForCurrentUser();
            model.selectedRecipeID = p;
            _controller.loadRecipe(model);
            return model;
        }

        public MyRecipeViewModel getRecipesByValue(string p)
        {
            var model = _controller.LoadMyRecipeViewModelForCurrentUser();
            model.recipeTerm = p;
            _controller.loadRecipesByValue(model);
            return model;
        }
    }
}